using System;
using System.Collections.Generic;
using System.Text;
using NBusiness.CodeDom;
using NBusiness.Properties;

namespace NBusiness.Data.Validation
{
    [Serializable]
    [ExpectedArgumentType(typeof(RequiredEventArgs))]
    public sealed class RequiredRule : ValidationRule
    {
        public RequiredRule(Type entityType, string field, RequiredEventArgs arg)
            : base(entityType, field, ValidateRequiredRule, arg, Resources.RequiredRuleMessage)
        { }

        public static bool ValidateRequiredRule<T>(T value, ValidationEventArgs e)
        {
            return value != null && !value.Equals(default(T));
        }

        public override ValidationRuleType Type
        {
            get { return ValidationRuleType.Error; }
        }
    }
}
